package com.guoyu.project.service;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.google.common.collect.Maps;
import com.guoyu.project.common.pagination.Pagination;
import com.guoyu.project.dao.AttachmentDao;
import com.guoyu.project.model.Attachment;
import com.guoyu.project.model.Project_Manage;

@Service
public class AttachmentService {

	@Resource
	private AttachmentDao attachmentDao;
	
	//添加
    public void saveAttachment(Attachment attachment) {
    	attachmentDao.save(attachment);;
    }

    //更新
    public void updateAttachment(Attachment attachment) {
    	attachmentDao.update(attachment);
    }

    /**
     * 删除
     */
    public void deleteById(Integer attachment_id) {
    	attachmentDao.deleteById(attachment_id);
    }

    /**
     * 根据id获取信息数据
     */
    public Attachment queryById(Integer attachment_id) {
        return attachmentDao.queryById(attachment_id);
    }

    /**
     * 根据条件分页查询信息数据
     *
     * @param offset
     * @param limit
     * @param params
     * @return
     */
    public Pagination<Attachment> queryAllAttachment(int offset, int limit, Map<String, Object> params) {
        // 根据条件获取总记录数
        int total = attachmentDao.queryAttachmentCount(params);

        // 构建分页对象，参数
        if (null == params) {
            params = Maps.newHashMap();
        }
        params.put(Pagination.OFFSET, offset);
        params.put(Pagination.LIMIT, limit);

        // 分页查询数据
        List<Attachment> pmList = attachmentDao.queryAllAttachment(params);
        return new Pagination(offset, limit, total, pmList);
    }

    public List<Attachment> queryAllAttachment(Map<String, Object> params) {
        return attachmentDao.queryAllAttachment(params);
    }
}